#include "RotatingObject.h"


RotatingObject::RotatingObject(float imass, Vector3f iposition, Vector3f iupper, Vector3f ilower)
{
	mass = imass;
	position = iposition;
	angular_velocity = 0;
	alignment = 0;
	hit = false;
	u_point = iupper;
	l_point = ilower;
	u_point.z = position.z;
	l_point.z = position.z;
	Vector3f axis = l_point - u_point;
	float x_angle = (asin((l_point.x - u_point.x) / axis.length()));
	float y_angle = 90 - x_angle;
	x_comp = x_angle / 90;
	y_comp = y_angle / 90;
}


RotatingObject::~RotatingObject(void)
{
}

void RotatingObject::rotate()
{
	myFrame.RotateWorld(angular_velocity,x_comp,y_comp,0.0f);
	alignment += angular_velocity;
}


void RotatingObject::update()
{
	if(hit)
	{
		float tangenitalV = velocity.length() + sin(alignment);
		angular_velocity += tangenitalV / impact_distance;
		hit = false;
	}
	if(angular_velocity != 0)
	{
		drag = angular_velocity * 0.1;
		if(direction_of_spin == CLCKWISE)
		{
			angular_velocity -= drag;
		}
		else
		{
			angular_velocity += drag;
		}
	}
}

